package com.shuorikeji.huohuo.ui.me;

import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.shuorikeji.huohuo.R;
import com.shuorikeji.huohuo.base.BasePresenterActivity;
import com.shuorikeji.huohuo.callback.ClickCallBack;
import com.shuorikeji.huohuo.mvp.AllPresenter;
import com.shuorikeji.huohuo.utils.BusinessUtils;
import com.shuorikeji.huohuo.utils.ToastShowUtil;

import butterknife.BindView;

public class TxActivity extends BasePresenterActivity<AllPresenter> {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.et_je)
    EditText etJe;
    @BindView(R.id.tv_tips)
    TextView tvTips;
    @BindView(R.id.tv_qb_tx)
    TextView tvQbTx;
    @BindView(R.id.tv_tx)
    TextView tvTx;

    private String ye;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getmImmersionBar().reset().statusBarColor(R.color.transparent).statusBarDarkFont(true, 0.2f).init();
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_tx);
    }

    @Override
    protected void initData() {
        initIntent();
        initClick();
    }

    private void initIntent() {
        Intent intent = getIntent();
        ye = intent.getStringExtra("YE");
        try {
            double douYe = Double.parseDouble(ye);
            String newYe = String.format("%.2f", douYe);
            tvTips.setText("当前可提现金额" + newYe + "元，");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void aliPaySq() {
        mPresenter.aliPaySq(true, "", new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        tx();
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(TxActivity.this, msg);
                        break;
                }
            }
        });
    }

    private void tx() {
        mPresenter.tx(true, Double.parseDouble(etJe.getText().toString()), 1, -1, 2, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(TxActivity.this, msg);
                        break;
                }
            }
        });
    }

    private void initClick() {
        ivBack.setOnClickListener(view -> {
            finish();
        });
        tvQbTx.setOnClickListener(view -> {
            try {
                double douYe = Double.parseDouble(ye);
                String newYe = String.format("%.2f", douYe);
                etJe.setText(newYe);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        tvTx.setOnClickListener(view -> {
            if (BusinessUtils.isEmpty(etJe.getText().toString())) {
                ToastShowUtil.showToastCenter(TxActivity.this, "请输入提现金额");
            } else {
                aliPaySq();
            }
        });
    }
}